import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Calculator extends JFrame {
	public static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField no1;
	private JTextField no2;
	private JTextField resultButton;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Calculator frame = new Calculator();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Calculator() {
		setTitle("Calculator");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 250, 217);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		no1 = new JTextField();
		no1.setBounds(10, 11, 86, 20);
		contentPane.add(no1);
		no1.setColumns(10);
		
		no2 = new JTextField();
		no2.setBounds(141, 11, 86, 20);
		contentPane.add(no2);
		no2.setColumns(10);
		
		JButton plusButton = new JButton("+");
		plusButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int result = (int)(Double.parseDouble(no1.getText()) + Double.parseDouble(no2.getText()));		
				resultButton.setText(String.valueOf(result));
			}
		});
		plusButton.setBounds(7, 42, 89, 23);
		contentPane.add(plusButton);
		
		JButton minusButton = new JButton("-");
		minusButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int result = (int)(Double.parseDouble(no1.getText()) - Double.parseDouble(no2.getText()));			
				resultButton.setText(String.valueOf(result));
			}
		});
		minusButton.setBounds(141, 42, 89, 23);
		contentPane.add(minusButton);
		
		JButton oriButton = new JButton("x");
		oriButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int result = (int)(Double.parseDouble(no1.getText()) * Double.parseDouble(no2.getText()));		
				resultButton.setText(String.valueOf(result));
			}
		});
		oriButton.setBounds(7, 76, 89, 23);
		contentPane.add(oriButton);
		
		JButton impButton = new JButton(":");
		impButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int result = (int)(Double.parseDouble(no1.getText()) / Double.parseDouble(no2.getText()));		
				resultButton.setText(String.valueOf(result));
			}
		});
		impButton.setBounds(141, 76, 89, 23);
		contentPane.add(impButton);
		
		
		JButton btnClear = new JButton("Clear");
		btnClear.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				no1.setText("");
				no2.setText("");
				resultButton.setText("");
			}
		});
		btnClear.setBounds(70, 144, 89, 23);
		contentPane.add(btnClear);
		
		JLabel lblResult = new JLabel("Result:");
		lblResult.setBounds(70, 110, 46, 14);
		contentPane.add(lblResult);
		
		resultButton = new JTextField();
		resultButton.setBounds(114, 107, 49, 20);
		contentPane.add(resultButton);
		resultButton.setColumns(10);
		
		
	}
}
